﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EstimationStudio.Core;

namespace EstimationStudio.UI
{
    public partial class FeatureControl : UserControl
    {
        public FeatureControl()
        {
            InitializeComponent();
        }

        public event EventHandler Changed;

        public Boolean Selected
        {
            get { return chkSelect.Checked; }
        }

        private void Control_Changed(object sender, EventArgs e)
        {
            if (Changed != null)
                Changed(this, EventArgs.Empty);
        }

        public void LoadFeature(Feature feature)
        {
            if (feature == null)
                return;

            txtTitle.Text = feature.Name;
            txtDescription.Text = feature.Description;
            txtSolutionNotes.Text = feature.SolutionNotes;
            txtRisks.Text = feature.Risks;
            txtEstimateBestCase.Text = feature.BestCase.ToString("N2");
            txtEstimateNominalCase.Text = feature.NominalCase.ToString("N2");
            txtEstimateWorstCase.Text = feature.WorstCase.ToString("N2");
        }

        public Feature UnloadFeature()
        {
            Double bestCase, nominalCase, worstCase;

            Double.TryParse(txtEstimateBestCase.Text, out bestCase);
            Double.TryParse(txtEstimateNominalCase.Text, out nominalCase);
            Double.TryParse(txtEstimateWorstCase.Text, out worstCase);

            var feature = new Feature
            {
                Name = txtTitle.Text,
                Description = txtDescription.Text,
                SolutionNotes = txtSolutionNotes.Text,
                Risks = txtRisks.Text,
                BestCase = bestCase,
                NominalCase = nominalCase,
                WorstCase = worstCase,
            };

            return feature;
        }
    }
}